/**
 * Created with CLion.
 * Description: 
 * User: cyber
 * Date: 2020-08-31
 * Time: 19:06
 */

#include <iostream>
#include <thread>
#include "Header.h"
 using namespace std;


void do_something_in_current_thread()
{

}
void f()
{
    int some_locate_state = 0;
    func my_func(some_locate_state);

    std::thread t(my_func);
    try {
        do_something_in_current_thread();
    }
    catch (...) {
        t.join();       //1
        throw ;
    }
    t.join();           //2
}
// 程序正常运行时，执行到2处；有异常时执行到1处

int main(){
    int some_local_state = 0;
    func my_func(some_local_state);
    std::thread my_thread(my_func);
    //不等待线程结束，新线程可能还在运行，因此建议使用join来确保编程结束后，主线程在退出
    my_thread.detach();     //my_thread.join();
}